import java.util.Scanner;

//move even numbers in array to the beginning
//													The input array is 3 6 1 8 4 0 6 2 8 
//													The output array is 8 6 2 8 4 0 6 1 3 
//													
//										**********************************************************			
//													
//													The input array is 2 6 1 7 
//													The output array is 2 6 1 7 
//
public class Assignment3 {
	
	public static void main(String args[]) {
		CalcAPI myapi = new CalcAPI();		
		System.out.println("Enter the number of inputs");
		Scanner s = new Scanner(System.in);
		int numOfInputs = s.nextInt();
		int[] myArray = new int[numOfInputs];
		for(int i=0;i<numOfInputs;i++) {
			System.out.println("Enter integer input #" + (i+1));
			myArray[i] = myapi.getIntInput();				
		}
		System.out.print("The input array is ");
		for(int i=0;i<numOfInputs;i++) {
			System.out.print(myArray[i] + " ");			
		}
		int counter = numOfInputs-1 ;
		for(int i=0;i<numOfInputs;i++) {
			//find the odd number from beginning of array 
			if(myapi.checkIfOdd(myArray[i])) {
				//find the first even number starting from end 
				for(int j=counter;j>=i;j--) {
					if(!myapi.checkIfOdd(myArray[j])) {
						//when u find even no, swap and remember this location "counter", everything from counter to end of array is already odd.
						int temp = myArray[j];
						myArray[j] = myArray[i];
						myArray[i] = temp;	
						counter = j-1;
						break;					
					}				
				}	
			}
		} 
		System.out.println();
		System.out.print("The output array is ");
		for(int i=0;i<numOfInputs;i++) {
			System.out.print(myArray[i] + " ");			
		}
		
	}

}
